﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tutorial
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void songBrowser_MouseEnter(object sender, MouseEventArgs e)
        {
            songBrowser.Background = Brushes.Orange;
        }

        private void songBrowser_MouseLeave(object sender, MouseEventArgs e)
        {
            songBrowser.Background = Brushes.White;
        }

        private void songBrowser_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
	        SongBrowserDirSelected();
        }

        private void songBrowser_KeyUp(object sender, KeyEventArgs e)
        {
	        if (e.Key == Key.Enter)
		        SongBrowserDirSelected();
        }
        /// <summary>
        /// Changes the current directory of the SongBrowser.
        /// </summary>
        private void SongBrowserDirSelected()
        {
            // Query the data source.
            SongBrowser sb = (SongBrowser)((ObjectDataProvider)Resources["SongBrowserDS"]).ObjectInstance;
            // Get the currently selected item
            var selectedDir = (MyDirectory)songBrowser.SelectedItem;
            
            // Make sure we only do this, if there is something selected
            if (selectedDir == null)
                return;
            
            // Set the current directory to the selected directory
            sb.CurrentDirectory = selectedDir;
        }
    }
}
